import Vue from 'vue'
import VueRouter from 'vue-router'


//解决vue-router报NavigationDuplicated: Avoided redundant navigation to current location 的问题
const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}


Vue.use(VueRouter);
const Login = ()=> import('../views/login/login.vue')
const Home = ()=> import('../views/home/home.vue')
const UserInfo =()=> import('../views/userInfo/index.vue')
const User =()=> import('../views/user/index.vue')
const Category =()=> import('../views/category/index.vue')
const Order =()=> import('../views/order/index.vue')
const Product =()=> import('../views/product/index.vue')
const Statistic =()=> import('../views/statistics/index.vue')
const Store =()=> import('../views/store/index.vue')
const Workspace =()=> import('../views/workspace/index.vue')
const StoreInfo =()=> import('../views/storeInfo/index.vue')
const AddUser =()=> import('../views/user/addUser.vue')
const AddStore =()=> import('../views/store/addStore.vue')
const Inventory =()=> import('../views/inventory/index.vue')
const AddCategory = ()=> import('../views/category/addCategory.vue')
const AddProduct = ()=> import('../views/product/addProduct.vue')
const AddInventory = ()=> import('../views/inventory/addInventory.vue')
const Purchase = ()=> import('../views/purchase/index.vue')
const MiniProgramsOrders = ()=> import('../views/order/miniProgramsOrder.vue')
const OfflineOrders = ()=> import('../views/order/offlineOrders.vue')
const OrderDetail = () => import('../views/order/orderDetail.vue')
const Vip = ()=> import('../views/vip/index.vue')

const routes = [
    {
        path:'/',
        name:'login',
        component:Login
    },
    {
        path:'/home',
        name:'home',
        component:Home,
        redirect:'/home/workspace',
        children:[
            {
                path:'/home/userInfo',
                name:'userInfo',
                component:UserInfo
            },
            {
                path:'/home/user',
                name:'user',
                component:User
            },
            {
                path:'/home/workspace',
                name:'workspace',
                component:Workspace
            },
            {
                path:'/home/category',
                name:'category',
                component:Category
            },
            {
                path:'/home/order',
                name:'order',
                component:Order,
                redirect:'/home/order/offlineOrders',
                children:[
                    {
                        path:'/home/order/offlineOrders',
                        name:'offlineOrders',
                        component:OfflineOrders
                    },
                    {
                        path:'/home/order/miniProgramsOrder',
                        name:'miniProgramsOrder',
                        component:MiniProgramsOrders
                    },
                ]
            },
            {
                path:'/home/product',
                name:'product',
                component:Product
            },
            {
                path:'/home/statistic',
                name:'statistic',
                component:Statistic
            },
            {
                path:'/home/store',
                name:'store',
                component:Store
            },
            {
                path:'/home/storeInfo',
                name:'storeInfo',
                component:StoreInfo
            },
            {
                path:'/home/addUser',
                name:'addUser',
                component:AddUser
            },
            {
                path:'/home/addStore',
                name:'addStore',
                component:AddStore
            },
            {
                path:'/home/inventory',
                name:'inventory',
                component:Inventory
            },
            {
                path:'/home/addCategory',
                name:'addCategory',
                component:AddCategory
            },
            {
                path:'/home/addProduct',
                name:'addProduct',
                component:AddProduct
            },
            {
                path:'/home/addInventory',
                name:'addInventory',
                component:AddInventory
            },
            {
                path:'/home/purchase',
                name:'purchase',
                component:Purchase
            },
            {
                path:'/home/orderDetail',
                name:'orderDetail',
                component:OrderDetail
            },
            {
                path:'/home/vip',
                name:'vip',
                component:Vip
            }
        ]
    },
    {
        path: "/404",
        component: () => import(/* webpackChunkName: "404" */ "@/views/404.vue"),
        meta: { title: "苍穹外卖", hidden: true, notNeedAuth: true }
      },
    {
        path: "*",
        redirect: "/404",
        meta: { hidden: true }
    }
]


const router = new VueRouter({
    routes
})

export default router